package bhbt.controller.admin.info;


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import bhbt.controller.core.BaseController;
import bhbt.model.Notice;
import bhbt.service.NoticeService;
import bhbt.utils.MapUtil;






/**
 * Created by Administrator on 2016/3/25.
 */
@Controller
 
public class NoticeShowController extends BaseController {
    @Resource
    private NoticeService noticeService;
   
   

    @RequestMapping("admin/info/noticeShow.shtml")
    public String show(HttpServletRequest request) throws Exception{
        Map formMap = getParameterMap(request);
        int id = MapUtil.getIntValue(formMap, "id");
        if(0 < id){
        	Notice notice = noticeService.getByKey(id);
           
            request.setAttribute("notice",notice);
        }
        return "admin/info/noticeShow";
       
    }
    
    
    @RequestMapping("admin/info/noticeUpdate.shtml")
    public String update(HttpServletRequest request, ModelMap model) throws Exception{
        Map formMap = getParameterMap(request);
        int id = MapUtil.getIntValue(formMap, "id");
       
        if(0 < id){
        	Map map2 = new HashMap();
        	map2.put("id",id);
        	map2.put("title",MapUtil.getString(formMap,"title"));
        	map2.put("content",MapUtil.getString(formMap,"content"));
        	
//        	notice= noticeService.getByKey(id);
//        	notice.setTitle(MapUtil.getString(formMap,"title"));
//        	notice.setContent(MapUtil.getString(formMap,"content"));
        	noticeService.update(map2);
            
        	
        	
        	setMessage(model,"更新成功！");
            Boolean result = true;
    		request.setAttribute("result", result);
    		Notice notice= noticeService.getByKey(id);
            request.setAttribute("notice",notice);
            
        }
        return "admin/info/noticeShow";
    }

     
    

}
